<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    {{template "header.html" .}}
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="javascript:">系统管理</a>
        <a href="javascript:">菜单管理</a>
        <a>
          <cite>菜单列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    {{/*<div class="layui-row">*/}}
        {{/*<form class="layui-form layui-col-md12 x-so layui-form-pane">*/}}
            {{/*<input class="layui-input" placeholder="分类名" name="cate_name">*/}}
            {{/*<button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon"></i>增加</button>*/}}
        {{/*</form>*/}}
    {{/*</div>*/}}
    {{/*<blockquote class="layui-elem-quote">每个tr 上有两个属性 cate-id='1' 当前分类id fid='0' 父级id ,顶级分类为 0，有子分类的前面加收缩图标<i class="layui-icon x-show" status='true'>&#xe623;</i></blockquote>*/}}
    <xblock>
        <button class="layui-btn"  lay-submit="" lay-filter="" onclick="x_admin_show('编辑','{{urlfor "SysMenuController.FormSysMenu"}}')"><i class="layui-icon"></i>添加菜单</button>

        <button class="layui-btn" style="background-color: #5FB878" onclick="modifyStatusByBatch('{{urlfor "SysMenuController.ModifySysMenuStatus"}}',1)"><i class="layui-icon layui-icon-play"></i>批量开启</button>
        <button class="layui-btn layui-bg-orange" onclick="modifyStatusByBatch('{{urlfor "SysMenuController.ModifySysMenuStatus"}}',0)"><i class="layui-icon layui-icon-pause"></i>批量关闭</button>
        <button class="layui-btn layui-btn-danger" onclick="deleteDataByBatch('{{urlfor "SysMenuController.DeleteSysMenu"}}')"><i class="layui-icon layui-icon-delete"></i>批量删除</button>

        <span class="x-right" style="line-height:40px">共有数据：{{.MenuList|len}} 条</span>
    </xblock>



    <table class="layui-table layui-form">
        <thead>
        <tr>
            <th width="10">
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th width="20">ID</th>
            <th width="20">FID</th>
            <th width="20">图标</th>
            <th width="80">菜单名称</th>
            <th width="80">URL</th>
            <th width="20">Level</th>
            <th width="30">PATH</th>
            <th width="250">操作</th>
            <th width="20">状态</th>
            <th width="120">操作</th>
        </thead>
        <tbody class="x-cate">

        {{range $key,$value := .MenuList}}

                <tr cate-id='{{$value.Id}}' fid='{{$value.MenuRootid}}' >
                    <td>
                        <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{{$value.Id}}'><i class="layui-icon">&#xe605;</i></div>
                    </td>
                    <td>{{$value.Id}}</td>
                    <td>{{$value.MenuRootid}}</td>
                    <td><i class="iconfont">{{str2html $value.MenuIcon}}</i></td>
                    <td>

                        {{if eq $value.MenuLevel 1}}
                            <i class="layui-icon x-show" status='true'>&#xe623;</i>
                            {{$value.MenuName}}
                        {{else}}
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|---{{$value.MenuName}}
                        {{end}}

                    </td>
                    <td>{{$value.MenuUrl}}</td>
                    <td>{{$value.MenuLevel}}</td>
                    <td>{{$value.MenuPath}}</td>
                    <td>
                        {{/*{{$value.MenuFuncs}}*/}}
                        {{range $k,$func := $value.FuncsInfo}}
                            <span class="layui-badge layui-bg-gray">{{$func.FuncName}}</span>&nbsp;
                        {{end}}
                    </td>
                    <td>
                        {{if eq $value.MenuStatus 1}}
                            <span class="layui-badge" style="background-color: #5FB878" >开启</span>
                        {{else}}
                            <span class="layui-badge layui-bg-orange">关闭</span>
                        {{end}}
                    </td>
                    <td class="td-manage">

                        <button class="layui-btn layui-btn layui-btn-xs"  onclick="x_admin_show('编辑','{{urlfor "SysMenuController.FormSysMenu" "menu_id" $value.Id}}')" >
                            <i class="layui-icon">&#xe642;</i>编辑
                        </button>

                        {{if eq $value.MenuStatus 1}}
                            <button style="background-color: #FFB800" class="layui-btn layui-btn layui-btn-xs "  onclick="modifyStatusByOne('{{urlfor "SysMenuController.ModifySysMenuStatus"}}',this,'{{$value.Id}}','0')" >
                                <i class="layui-icon layui-icon-pause"></i> 关闭
                            </button>
                        {{else}}
                            <button style="background-color: #5FB878" class="layui-btn layui-btn layui-btn-xs "  onclick="modifyStatusByOne('{{urlfor "SysMenuController.ModifySysMenuStatus"}}',this,'{{$value.Id}}','1')" >
                                <i class="layui-icon layui-icon-play"></i> 开启
                            </button>
                        {{end}}

                        <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="deleteDataByOne('{{urlfor "SysMenuController.DeleteSysMenu"}}',this,'{{$value.Id}}')" href="javascript:;" >
                            <i class="layui-icon">&#xe640;</i>删除
                        </button>

                    </td>
                </tr>

        {{end}}

        </tbody>
    </table>
</div>
<style type="text/css">

</style>
<script>
    layui.use(['form'], function(){
        form = layui.form;
    });

    var urlModifyMenuStatus = '{{urlfor "SysMenuController.ModifySysMenuStatus"}}';
    var urlDeleteMenu = '{{urlfor "SysMenuController.DeleteSysMenu"}}';

    // 批量删除
    function deleteAllSysMenu()
    {
        var idArr = [];
        $(".layui-form-checked").each(function () {
            var currDataId = $(this).attr("data-id");
            if ("undefined" != typeof(currDataId)){
                idArr.push(currDataId)
            }
        });

        if(!idArr.length){
            layer.msg("未选中记录",{icon:1,time:1000});
            return
        }

        layer.confirm('确认要执行操作吗？',{btn:['确定','取消']},function(index){
            $.ajax({
                url: decodeURI(urlDeleteMenu),
                data: {"menu_ids":idArr.join()},
                type: "get",
                dataType: "json",
                success: function (data) {
                    var messge = "网络繁忙...";
                    if(data.Message) {
                        messge = data.Message;
                    }

                    layer.msg(messge,{icon:1,time:1000},function () {
                        if(data.Code > 0){
                            window.location.href=data.Data;
                        }
                    });
                }
            });
            return false;
        });
    }

    // 批量修改状态
    function modifyAllMenuStatus(status)
    {
        var idArr = [];
        $(".layui-form-checked").each(function () {
            var currDataId = $(this).attr("data-id");
            if ("undefined" != typeof(currDataId)){
                idArr.push(currDataId)
            }
        });

        if(!idArr.length){
            layer.msg("未选中记录",{icon:1,time:1000});
            return
        }

        layer.confirm('确认要执行操作吗？',{btn:['确定','取消']},function(index){
            $.ajax({
                url: decodeURI(urlModifyMenuStatus),
                data: {"menu_ids":idArr.join(),"menu_status":status},
                type: "get",
                dataType: "json",
                success: function (data) {
                    var messge = "网络繁忙...";
                    if(data.Message) {
                        messge = data.Message;
                    }

                    layer.msg(messge,{icon:1,time:1000},function () {
                        if(data.Code > 0){
                            window.location.href=data.Data;
                        }
                    });
                }
            });
            return false;
        });
    }

    // 单条修改状态
    function modifySysMenuStatus(obj,id,status)
    {
        layer.confirm('确认要执行操作吗？',{btn:['确定','取消']},function(index){
            $.ajax({
                url: decodeURI(urlModifyMenuStatus),
                data: {"menu_ids":id,"menu_status":status},
                type: "get",
                dataType: "json",
                success: function (data) {
                    var messge = "网络繁忙...";
                    if(data.Message) {
                        messge = data.Message;
                    }

                    layer.msg(messge,{icon:1,time:1000},function () {
                        if(data.Code > 0){
                            window.location.href=data.Data;
                        }
                    });
                }
            });
            return false;
        });
    }

    // 单条删除
    function deleteSysMenu(obj,id)
    {
        layer.confirm('确认要执行操作吗？',{btn:['确定','取消']},function(index){
            $.ajax({
                url: decodeURI(urlDeleteMenu),
                data: {"menu_ids":id},
                type: "get",
                dataType: "json",
                success: function (data) {
                    var messge = "网络繁忙...";
                    if(data.Message) {
                        messge = data.Message;
                    }

                    layer.msg(messge,{icon:1,time:1000},function () {
                        if(data.Code > 0){
                            window.location.href=data.Data;
                        }
                    });
                }
            });
            return false;
        });
    }

</script>

</body>
</html>